<?php
/**
 * Created by PhpStorm.
 * User: dt
 * Date: 2017/9/19
 * Time: 10:50
 */

namespace backend\models;

use yii\base\Model;
use backend\base\BaseModel;

class SignModel extends BaseModel
{

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'sign';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'id',
            'areaName' => '区域名称',
            'areaCode' => '区域code',
            'isSign' => '是否签约',
            'areaLevel' => '区域级别',
            'cityCode' => '城市code',
            'cityName' => '城市名称',
        ];
    }

    /*
     * 获取列表
     */
    public function list($data = [])
    {
        $condition = "1=1";
        if(!empty($data['city'])){
            $condition .= " and cityCode = ".$data['city'];
        }
        if(!empty($data['province'])){
            $code_sup = (substr($data['province'], 0 ,2)+1).'0000';
            $condition .= " and cityCode > ".$data['province']." and cityCode <".$code_sup;
        }
        if(!empty($data['title'])){
            if(!empty($data['type']) && $data['type'] == 1){
                $condition .= " and areaName like '%".$data['title']."%'";
            }
            if(!empty($data['type']) && $data['type'] == 2){
                $condition .= " and cityName like '%".$data['title']."%'";
            }
        }
        if(!empty($data['sign'])){
            $condition .= " and isSign = ".($data['sign']-1);
        }
        $result = self::find()->distinct()->where($condition)->asArray()->all();
        return $result;
    }
}